<?php

require ("sharedResources.php");

$sid = '';
try {
	// We need a SID (session ID) in order to operate
	$sid = login ( 'admin', 'admin' );
	echo 'sid: ' . $sid . PHP_EOL;

	
	$folderName = "PHP created folder";
	$parentFolder = DEFAULT_WORKSPACE;
	$FOLDER_TYPE_DEFAULT = 0; // default folder type
	
	$folder = array ('description' => null, 'id' => 0, 'name' => $folderName, 'parentId' => $parentFolder, 'type' =>  $FOLDER_TYPE_DEFAULT);
	
	$cfp = array ('sid' => $sid, 'folder' => $folder );
	
	/*****************
	 * CREATE
	 * ***************/
	$result = $folderClient->create ( $cfp );
	print_r ( "CREATE\r\n" );
	print_r ( $result );
	
	$folderID = $result->folder->id;
	
	/*****************
	 * READ
	 * ***************/
	$cfp = array ('sid' => $sid, 'folderId' => $folderID );
	$result = $folderClient->getFolder ( $cfp );
	print_r ( "READ\r\n" );
	print_r ( $result );
	
	/*****************
	 * UPDATE
	 * ***************/
	$cfp = array ('sid' => $sid, 'folderId' => $folderID, 'name' => "PHP renamed folder" );
	$result = $folderClient->rename ( $cfp );
	print_r ( "UPDATE\r\n" );
	print_r ( $result );
  
  // Reread
	$cfp = array ('sid' => $sid, 'folderId' => $folderID );
	$result = $folderClient->getFolder ( $cfp );
	print_r ( "RE-READ\r\n" );
	print_r ( $result );  
	
	/*****************
	 * DELETE
	 * ***************/
	$cfp = array ('sid' => $sid, 'folderId' => $folderID );
	$result = $folderClient->delete ( $cfp );
	print_r ( "DELETE\r\n" );
	print_r ( $result );
	
	//unset ( $folderClient );
} catch ( SoapFault $e ) {
	print_r ( $e );
}

// Always we need to logout in order to release connection slot
logout ( $sid );
?> 
	